home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 December / december_2001.iso / Browsers / Netscape 6.1 / browser.xpi / bin / chrome / comm.jar / content / navigator / urlbarBindings.xml < prev    next >
Encoding:
Extensible Markup Language  |  2001-06-19  |  12.7 KB  |  357 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="urlbarBindings"
  4.           xmlns="http://www.mozilla.org/xbl"
  5.           xmlns:html="http://www.w3.org/1999/xhtml"
  6.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  7.  
  8.   <binding id="autocomplete-result-popup" extends="chrome://global/content/autocomplete.xml#autocomplete-result-popup">
  9.     <content menugenerated="true" orient="vertical">
  10.       <xul:box class="autocomplete-result-box" flex="1">
  11.         <xul:outliner anonid="outliner" class="autocomplete-outliner" flex="1">
  12.           <xul:outlinerbody anonid="outlinerbody" class="autocomplete-outlinerbody" flex="1"/>
  13.         </xul:outliner>
  14.       </xul:box>
  15.       <xul:box role="search-box" class="autocomplete-search-box"/>
  16.     </content>
  17.     
  18.     <implementation>
  19.       <constructor><![CDATA[
  20.         // listen for changes to default search engine
  21.         this.mPrefs.addObserver("browser.search", this.mSearchPrefObserver);
  22.       ]]></constructor>
  23.  
  24.       <destructor><![CDATA[
  25.         this.mPrefs.removeObserver("browser.search", this.mSearchPrefObserver);
  26.       ]]></destructor>
  27.  
  28.       <property name="selectedIndex"
  29.                 onget="return this.textbox.view.selectedIndex;">
  30.         <setter>
  31.           this.mSelectedIndex = val;
  32.           if (val == null)
  33.             this.mSearchBox.selectedIndex = null;
  34.             
  35.           return val;
  36.         </setter>
  37.      </property>
  38.  
  39.       <property name="mSelectedIndex">
  40.         <setter>
  41.           this.textbox.view.selectedIndex = val;
  42.           return val;
  43.         </setter>
  44.      </property>
  45.  
  46.       <property name="defaultSearchEngine"
  47.                 onget="return this.textbox.getAttribute('defaultSearchEngine') == 'true';"
  48.                 onset="this.textbox.setAttribute('defaultSearchEngine', val); return val;"/>
  49.  
  50.       <property name="mSearchBox">
  51.          document.getAnonymousElementByAttribute(this, "role", "search-box");
  52.       </property>
  53.  
  54.       <property name="mPrefs">
  55.         Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref);
  56.       </property>
  57.  
  58.       <property name="mSearchPrefObserver"><![CDATA[
  59.         ({
  60.           resultsPopup: this,
  61.           
  62.           Observe: function() {
  63.             this.resultsPopup.updateEngines();
  64.           }
  65.         });
  66.       ]]></property>
  67.  
  68.       <property name="mInputListener"><![CDATA[
  69.         (function(aEvent) {
  70.           // don't update when the user is using the up/down keys
  71.           if (!this.ignoreInputEvent)
  72.             this.resultsPopup.mSearchBox.searchValue = this.value;
  73.         });
  74.       ]]></property>
  75.  
  76.       <property name="mEnginesReady">false</property>
  77.       
  78.       <!-- initialize the columns in the outliner -->
  79.       <method name="initColumns">
  80.         <body><![CDATA[
  81.           this.addColumn({id: "value", flex: 2});
  82.           this.addColumn({id: "comment", flex: 1});
  83.         ]]></body>
  84.       </method>
  85.  
  86.       <method name="getOverrideValue">
  87.         <body><![CDATA[
  88.           if (this.mSearchBox.selectedIndex != null)
  89.             return this.mSearchBox.getOverrideValue();
  90.           return null;
  91.         ]]></body>
  92.       </method>
  93.  
  94.       <method name="addEngine">
  95.         <parameter name="aEngineId"/>
  96.         <parameter name="aName"/>
  97.         <parameter name="aIcon"/>
  98.         <parameter name="aSearchBarUrl"/>
  99.         <body><![CDATA[
  100.           var box = document.createElement("box");
  101.           box.setAttribute("class", "autocomplete-search-engine");
  102.           box.setAttribute("searchEngine", aEngineId);
  103.           box.setAttribute("name", aName);
  104.           box.setAttribute("icon", aIcon);
  105.           box.setAttribute("searchBarUrl", aSearchBarUrl);
  106.           box.setAttribute("engineIndex", this.childNodes.length);
  107.           this.mSearchBox.appendChild(box);
  108.         ]]></body>
  109.       </method>
  110.  
  111.       <method name="clearEngines">
  112.         <body><![CDATA[
  113.           var kids = this.mSearchBox.childNodes;
  114.           for (var i = kids.length-1; i >= 0; --i)
  115.             this.mSearchBox.removeChild(kids[i]);
  116.         ]]></body>
  117.       </method>
  118.    
  119.       <method name="updateEngines">
  120.         <body><![CDATA[
  121.           var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
  122.                       .getService(Components.interfaces.nsIRDFService);
  123.           var ds = rdf.GetDataSource("rdf:internetsearch");
  124.                       
  125.           const kNC_Name = rdf.GetResource("http://home.netscape.com/NC-rdf#Name");
  126.           const kNC_Icon = rdf.GetResource("http://home.netscape.com/NC-rdf#Icon");
  127.           const kNC_searchBarUrl = rdf.GetResource("http://home.netscape.com/NC-rdf#actionBar");
  128.         
  129.           var defaultEngine = null;
  130.           try {
  131.             defaultEngine = this.mPrefs.CopyUnicharPref("browser.search.defaultengine");
  132.           } catch(ex) {
  133.             this.ensureDefaultEnginePrefs(rdf, ds);
  134.             defaultEngine = this.mPrefs.CopyUnicharPref("browser.search.defaultengine");
  135.           }
  136.           
  137.           if (defaultEngine) {
  138.             this.clearEngines();
  139.             
  140.             if (ds) {
  141.               var res = rdf.GetResource(defaultEngine);
  142.               try {
  143.                  searchBarUrl = this.readRDFString(ds, res, kNC_searchBarUrl);
  144.               } catch(ex) {
  145.                 searchBarUrl = null;
  146.               }
  147.                 this.addEngine(res.Value, 
  148.                               this.readRDFString(ds, res, kNC_Name),
  149.                               this.readRDFString(ds, res, kNC_Icon),
  150.                               searchBarUrl);                                                    
  151.             }
  152.           }
  153.           
  154.           this.mEnginesReady = true;
  155.         ]]></body>
  156.       </method>
  157.  
  158.       <method name="ensureDefaultEnginePrefs">
  159.         <parameter name="aRDF"/>
  160.         <parameter name="aDS"/>
  161.         <body><![CDATA[
  162.           var defaultName = this.mPrefs.getLocalizedUnicharPref("browser.search.defaultenginename");
  163.           const kNC_Root = aRDF.GetResource("NC:SearchEngineRoot");
  164.           const kNC_child = aRDF.GetResource("http://home.netscape.com/NC-rdf#child");
  165.           const kNC_Name = aRDF.GetResource("http://home.netscape.com/NC-rdf#Name");
  166.           
  167.           var arcs = aDS.GetTargets(kNC_Root, kNC_child, true);
  168.           while (arcs.hasMoreElements()) {
  169.             var engineRes = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
  170.             var name = this.readRDFString(aDS, engineRes, kNC_Name);
  171.             if (name == defaultName)
  172.               this.mPrefs.SetUnicharPref("browser.search.defaultengine", engineRes.Value);
  173.           }
  174.         ]]></body>
  175.       </method>
  176.  
  177.       <method name="readRDFString">
  178.         <parameter name="aDS"/>
  179.         <parameter name="aRes"/>
  180.         <parameter name="aProp"/>
  181.         <body><![CDATA[
  182.           var n = aDS.GetTarget(aRes, aProp, true);
  183.           if (n)
  184.              return n.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  185.         ]]></body>
  186.       </method>
  187.  
  188.       <method name="selectBy">
  189.         <parameter name="aDir"/>
  190.         <parameter name="aAmount"/>
  191.         <body><![CDATA[
  192.           var bx = this.outliner.outlinerBoxObject;
  193.           var view = bx.view;
  194.           if (this.selectedIndex == null && aDir < 0) {
  195.             var sel = this.mSearchBox.selectBy(aDir, aAmount);
  196.             if (sel != null)
  197.               return null;
  198.           } 
  199.           
  200.           var sel = this.getNextIndex(aDir, aAmount, this.selectedIndex, view.rowCount-1);
  201.           this.mSelectedIndex = sel;
  202.  
  203.           if (sel == null && aDir > 0)
  204.             this.mSearchBox.selectBy(aDir, aAmount);
  205.           else if (this.mSearchBox.selectedIndex != null)
  206.             this.mSearchBox.selectedIndex = null;
  207.             
  208.           return sel;
  209.         ]]></body>
  210.       </method>
  211.     </implementation>
  212.  
  213.     <handlers>
  214.       <handler event="create"><![CDATA[
  215.         if (!this.mEnginesReady && this.defaultSearchEngine)
  216.           this.updateEngines();
  217.           this.textbox.addEventListener("input", this.mInputListener, false);
  218.         if ("searchValue" in this.mSearchBox)
  219.           this.mSearchBox.searchValue = this.textbox.value;
  220.         else
  221.           this.mSearchBox.setAttribute("searchvalue", this.textbox.value);
  222.       ]]></handler>
  223.       
  224.       <handler event="destroy"><![CDATA[
  225.         this.textbox.removeEventListener("input", this.mInputListener, false);
  226.       ]]></handler>      
  227.     </handlers>
  228.   </binding>
  229.  
  230.   <binding id="autocomplete-search-box">
  231.     <content orient="vertical"/>
  232.     
  233.     <implementation>
  234.       <constructor><![CDATA[
  235.         var text = this.getAttribute("searchvalue");
  236.         if (text)
  237.           this.searchValue = text;
  238.         
  239.         this.mSelectedIndex = null;
  240.       ]]></constructor>
  241.       
  242.       <property name="parentMouseoverListener">
  243.         // ensure that if a result menuitem is moused-over, any
  244.         // search selection is cleared
  245.         (function(aEvent) {
  246.           if (aEvent.target.nodeName == "menuitem")
  247.             this.mSearchBox.selectedIndex = null;
  248.          })
  249.       </property>
  250.       
  251.       <property name="parentDestroyListener">
  252.         // ensure that if the popup closes, any search selection is cleared
  253.         (function(aEvent) {
  254.            this.mSearchBox.selectedIndex = null;
  255.          })
  256.       </property>
  257.       
  258.       <property name="activeChild" 
  259.                 onget="return this.childNodes[this.mSelectedIndex]"/>
  260.  
  261.       <property name="selectedIndex">
  262.         <getter>return this.mSelectedIndex;</getter>
  263.         
  264.         <setter><![CDATA[
  265.           if (this.mSelectedIndex != null)
  266.             this.activeChild.removeAttribute("menuactive");
  267.           
  268.           this.mSelectedIndex = val;
  269.  
  270.           if (val != null) {
  271.             this.parentNode.mSelectedIndex = null;
  272.             this.parentNode.addEventListener("mouseover", this.parentMouseoverListener, false);
  273.             this.parentNode.addEventListener("destroy", this.parentDestroyListener, false);
  274.             if (this.activeChild)
  275.               this.activeChild.setAttribute("menuactive", "true");
  276.           } else {
  277.             this.parentNode.removeEventListener("mouseover", this.parentMouseoverListener, false);
  278.             this.parentNode.removeEventListener("destroy", this.parentDestroyListener, false);
  279.           }
  280.         ]]></setter>
  281.       
  282.       </property>
  283.       
  284.       <property name="searchValue">
  285.         <getter><![CDATA[
  286.           return this.mSearchValue;
  287.         ]]></getter>
  288.         <setter><![CDATA[
  289.           this.mSearchValue = val;
  290.           var kids = this.childNodes;
  291.           for (var i = 0; i < kids.length; ++i) {
  292.             var name = kids[i].getAttribute("name");
  293.             kids[i].setAttribute("label", "Search " + name + " for \"" + val + "\"");
  294.           }
  295.         ]]></setter>
  296.       </property>
  297.       
  298.       <method name="selectBy">
  299.         <parameter name="aDir"/>
  300.         <parameter name="aAmount"/>
  301.         <body><![CDATA[
  302.           var sel = this.parentNode.getNextIndex(aDir, aAmount, this.selectedIndex, this.childNodes.length-1);
  303.           this.selectedIndex = sel;
  304.           return sel;
  305.         ]]></body>
  306.       </method>
  307.  
  308.       <method name="getOverrideValue">
  309.         <body><![CDATA[
  310.           var item = this.activeChild;
  311.           if (item) {
  312.             const ISEARCH_CONTRACTID = "@mozilla.org/rdf/datasource;1?name=internetsearch";
  313.             const nsIInternetSearchService = Components.interfaces.nsIInternetSearchService;           
  314.             var searchService = Components.classes[ISEARCH_CONTRACTID].getService(nsIInternetSearchService);
  315.             var searchEng = item.getAttribute("searchEngine");
  316.             var searchEngUrl = item.getAttribute("searchBarUrl");
  317.             var escapedSearch = escape(this.mSearchValue)
  318.             if (searchEngUrl) {
  319.                 searchEngUrl += escapedSearch;
  320.                 return searchEngUrl;
  321.             } else {
  322.               return searchService.GetInternetSearchURL(item.getAttribute("searchEngine"),escapedSearch);
  323.             }
  324.           }
  325.           return null;
  326.         ]]></body>
  327.       </method>
  328.  
  329.     </implementation>
  330.  
  331.     <handlers>
  332.       <handler event="mouseup">
  333.         this.parentNode.textbox.onResultClick();
  334.       </handler>
  335.     </handlers>
  336.  
  337.   </binding>
  338.  
  339.   <binding id="autocomplete-search-engine">
  340.     <content>
  341.       <xul:image class="autocomplete-search-engine-img" inherits="src=icon"/>
  342.       <xul:text class="autocomplete-search-engine-text" inherits="value=label"/>
  343.     </content>
  344.     
  345.     <handlers>
  346.       <handler event="mouseover">
  347.         this.parentNode.selectedIndex = this.getAttribute("engineIndex");
  348.       </handler>
  349.  
  350.       <handler event="mouseout">
  351.         this.parentNode.selectedIndex = null;
  352.       </handler>
  353.     </handlers>
  354.   </binding>
  355.   
  356. </bindings>
  357.